package cn.gson.crm.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.Backrecord;
import cn.gson.crm.model.pojo.OrderResult;
import cn.gson.crm.model.vo.BackRecordVO;
import cn.gson.crm.service.BackRecordService;

@Controller
public class BackRecordControl {
	@Autowired
	private BackRecordService bService;

	@GetMapping("/toBackRecord")
	public String toBackRecord() {
		return "zj/backRecord";
	}

	@GetMapping("/getAllBackRecord")
	@ResponseBody
	public Map getAllBackRecord(int page, int rows) {
		Map map = new HashMap<>();
		Long count = bService.count();
		List<BackRecordVO> list = bService.getAllBackRecord(page, rows);
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
	
	@GetMapping("deleteBr")
	@ResponseBody
	public OrderResult deleteBr(Long brId) {
		try {
			bService.deleteBr(brId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	@PostMapping("/addBackRecord")
	@ResponseBody
	public OrderResult addBackRecord(Backrecord b,Long coIdvo) {
		System.out.println(b.getBrId());
		try {
			bService.addBackRecord(b,coIdvo);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
	
	/*@PostMapping("/editBackRecord")
	@ResponseBody
	public OrderResult editBackRecord(Backrecord b,Long coIdd) {
		System.out.println(b.getBrId());
		try {
			bService.editRecord(b,coIdd);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}		
	}*/
	
	@GetMapping("/getBackRecordById")
	@ResponseBody
	public BackRecordVO getBackRecordById(Long brId) {
		return bService.getOrderById(brId);
	}
}
